// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, View, Image, TouchableOpacity, ImageBackground, FlatList, RefreshControl } from 'react-native';

// 引入第三方依赖
import _ from 'lodash';
import pureRender from 'pure-render-decorator';

// antd 按需加载
import { ActivityIndicator } from '@ant-design/react-native';

// 引入 处理数据 所需文件
import { } from './module.js'

// 引入样式
import Styles from './style.js';

// 引入公用组件
import { Results } from '../../components/index.js'

// 引入工具包
import { size, ScreenWidth } from '../../util/utils.js'

class ReFlatList extends Component {
	static propTypes = {

	}

	constructor(props) {
		super(props)
		this.state = {}
	}

	ListEmptyComponent = () => {
		const { data } = this.props
		if (data.error) {
			return (
				<View style={{ padding: 20, }}>
					<Text style={{ fontSize: 14, color: '#fff', lineHeight: 16, textAlign: 'center' }}>出错了</Text>
				</View>
			)
		}
		if (data.pageNum == 0) {
			return (
				<View style={{ padding: 20, }}>
					<Text style={{ fontSize: 14, color: '#fff', lineHeight: 16, textAlign: 'center' }}>没有数据</Text>
				</View>
			)
		}
		return (
			<View style={{ padding: 20, }}>
				<Text style={{ fontSize: 14, color: '#fff', lineHeight: 16, textAlign: 'center' }}>加载中</Text>
			</View>
		)
	}

	ListFooterComponent = () => {
		const { data } = this.props
		console.log(data)
		if (data.list.length > 0) {
			if (data.list.length < data.total) {
				return (
					<View style={{ padding: 20, }}>
						<ActivityIndicator color="#fff" text="正在加载" />
					</View>
				)
			} else {
				return (
					<View style={{ padding: 20, }}>
						<Text style={{ fontSize: 14, color: '#fff', lineHeight: 16, textAlign: 'center' }}>到底了</Text>
					</View>
				)
			}
		}
		return null
	}

	render() {
		const { style, flatListStyle, progressBackgroundColor, data, ...props } = this.props
		return (
			<View style={{
				flex: 1,
				...style
			}}>
				<FlatList
					style={{
						flex: 1,
						...flatListStyle
					}}
					keyExtractor={(item, index) => index.toString()}
					ListEmptyComponent={this.ListEmptyComponent}
					ListFooterComponent={this.ListFooterComponent}
					onEndReachedThreshold={.0000001}
					data={data.list}
					{...props}
				/>
			</View>
		)
	}
}

export default pureRender(ReFlatList)
